<script type="text/javascript">
    {literal}
        $(document).ready(function() {
            $("#fulltext").keyup(function(event){
                if(event.keyCode == 13){
                    setFulltext($('#fulltext').val(),'list_of_users_fulltext')
                }
            });
            $("#fulltext").focus();
        });
    {/literal}
</script>

<ul class="subNavig">
    <li><a href="{$data.root}?input=list_of_clients">Clients</a></li>
    <li><a href="{$data.root}?input=list_of_users">Users</a></li>
    <li><a href="{$data.root}?input=list_of_tariffs">Tariffs</a></li>
    <li><a href="{$data.root}?input=fixed_expense">Fixed expenses</a></li>
</ul>
<h2 class="pageTitle">List of users</h2>
{include $data.pathToError}
{if $data.currentFilter || $data.currentFulltext!=''}
    <div class="menu-list bgDark">
        <b>Current filter:</b> 
        <ul>
            {foreach $data.currentFilter as $filter => $value}
                <li>{$filter} = <i>{$value}</i> [<a href="javascript: cancelFilter('{$filter}','list_of_users_filter')" class="baseLink">Cancel</a>]</li>
            {/foreach}
            {if $data.currentFulltext != ''}
                <li>Fulltext = <i>{$data.currentFulltext}</i> [<a href="javascript: cancelFulltext('list_of_users_fulltext')" class="baseLink">Cancel</a>]</li>
            {/if}
        </ul>
    </div>
{/if}
<div class="menu-list">
    Fulltext search: <input id="fulltext" type="text" value="{if $data.currentFulltext != ''}{$data.currentFulltext}{/if}" /><input value="Search" type="button" onclick="setFulltext($('#fulltext').val(),'list_of_users_fulltext')" />
</div>
<form action="{$data.root}?input=list_of_users" method="post" id="addingUser">
    <div class="menu-list">
        <a href="{$data.root}?input=add_user" class="basicButton">Add user</a>
        <select name="action" onchange="submitForm('addingUser')">
            <option value="">Actions ...</option>
            <option value="deleteUsers">Delete user(s)</option>
        </select>
    </div>
    <table class="list">
        <tr>
            <th><input type="checkbox" id="checkAll" onchange="checkIt('checkAll')" /></th>
            <th><a href="javascript: order('name','list_of_users_order')">Name {if $data.currentOrder.0=="name"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
            <th><a href="javascript: order('surname','list_of_users_order')">Surname {if $data.currentOrder.0=="surname"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
            <th><a href="javascript: order('email','list_of_users_order')">Email {if $data.currentOrder.0=="email"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
            <th><a href="javascript: order('telephone','list_of_users_order')">Telephone {if $data.currentOrder.0=="telephone"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
            <th><a href="javascript: order('login','list_of_users_order')">Login {if $data.currentOrder.0=="login"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
            <th><a href="javascript: order('client','list_of_users_order')">Client {if $data.currentOrder.0=="client"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
            <th><a href="javascript: order('userlevel','list_of_users_order')">Userlevel {if $data.currentOrder.0=="userlevel"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
            <th><a href="javascript: order('active','list_of_users_order')">Active {if $data.currentOrder.0=="active"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
            <th><a href="javascript: order('prefered','list_of_users_order')">Prefered {if $data.currentOrder.0=="prefered"}<img src="{$data.root}images/{$data.currentOrder.1}.png" height="14" width="14" />{/if}</a></th>
        </tr>
        {assign var=counter value=1}
        {foreach $data.users as $key => $user}
            {if $counter==1}
                {assign var=bgClass value='bgDark'}
            {else}
                {assign var=bgClass value='bgLight'}
            {/if}
            <tr class="{$bgClass}">
                {if $counter==1}
                    {assign var=counter value=2}
                {else}
                    {assign var=counter value=1}
                {/if}
                <td>
                    <input name="userId[]" value="{$user.users_id}" class="userselector" type="checkbox" />
                </td>
                <td><a class="filterLink" href="{$data.root}?input=edit_user&user={$user.users_id}">{$user.name}</a></td>
                <td><a class="filterLink" href="{$data.root}?input=edit_user&user={$user.users_id}">{$user.surname}</a></td>
                <td class="center">{$user.email}</td>
                <td class="center">{$user.telephone}</td>
                <td class="center">{$user.login}</td>
                <td class="center"><a class="filterLink" href="javascript: filter('client','{$user.client}','list_of_users_filter')">{$user.client_info.name}</a></td>
                <td class="center"><a class="filterLink" href="javascript: filter('userlevel','{$user.userlevel}','list_of_users_filter')">{$user.userlevel_info}</a></td>
                <td class="center">
                    <a class="filterLink" href="javascript: filter('active','{$user.active}','list_of_users_filter')">
                        {if $user.active == 0}
                            No
                        {else}
                            Yes
                        {/if}
                    </a>
                </td>
                <td class="center">
                    <a class="filterLink" href="javascript: filter('prefered','{$user.prefered}','list_of_users_filter')">
                        {if $user.prefered == 0}
                            No
                        {else}
                            Yes
                        {/if}
                    </a>
                </td>
            </tr>
        {/foreach}
    </table>
</form>
<div class="menu-list">
    <span class="pager">{$data.pager}</span>
    Records per page
    <select class="pager" size="1" onchange="changeRecordsPerPage(this.value, 'list_of_users_pager')">
        <option {if $smarty.session.list_of_users_pager==20}selected="selected"{/if} value="20">20</option>
        <option {if $smarty.session.list_of_users_pager==50}selected="selected"{/if} value="50">50</option>
        <option {if $smarty.session.list_of_users_pager==100}selected="selected"{/if} value="100">100</option>
    </select>
  Count: {$data.total_count}
</div>